<template>
	<view class="cooperation">
		<view class="coopera_bann">
			<image class="coopera_bann_img" src="../../static/images/hehuoren.png" mode=""></image>
		</view>
		<!--不是合伙人页面 -->
		<view class="peration_list">
			<view class="peration_item" v-for="(item,index) in partnerList.partnerList" :key='item.id' @click="viewPartner(item)">  
				<image class="peration_item_t" :src="item.level_icons" mode=""></image>  
				<view class="peration_item_c">
					<text style="line-height: 60rpx;">{{item.agency_level}}</text> 
					<text style="height: 30rpx;"></text>
					<text>添加合伙人,收获更多可能</text>
				</view>
				<image style="width: 46rpx; height: 46rpx; margin-bottom: 100rpx;" src="../../static/images/arrow.png" mode=""></image> 
			</view>								
					   <!-- {{partnerType}} -->
			<view class="peration_item" @click="viewPartners" v-if="partnerType != 0"> 
				 <image class="peration_item_t" :src="partnerImg.promote_img" mode=""></image>  
				<view class="peration_item_c">
					<text>{{partnerImg.promote_txt}}</text> 
					<text style="height: 100rpx;"></text>
					<text style="display: none;">添加合伙人,收获更多可能</text>
				</view>
				<image style="width: 46rpx; height: 46rpx; margin-bottom: 100rpx;" src="../../static/images/arrow.png" mode=""></image> 
			</view>
		</view>
	</view>
</template>

<script>
	import {
		isPartner,
		getAgencyLevel
	} from '@/api/user'
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				// 1 是合伙人 0 不是合伙人
				partnerType: null,
				partnerList: {
					partnerList:[] 
				},
				partnerImg: {},
				goUrl: '',
				 
			};
		},
		computed: mapGetters(['isLogin']),
		onShow() {
			this.isPartners()
		},
		methods: {
			// 获取合伙人类型
			isPartners() {
				isPartner().then(res => {
					if (res.status === 200) {
						this.partnerType = res.data.status
						this.partnerImg = res.data.result 
						this.getAgencyLevel()
						// 如果当前 状态是1(是合伙人) 获取代理等级  
						// this.partnerType == 1 ? console.log('是合伙人')  : this.getAgencyLevel()
					}
				})
			},
			// 获取代理等级
			getAgencyLevel() {
				let that = this
				getAgencyLevel().then(res => {
					if (res.status == 200) {
						let {
							data
						} = res.data.result
						that.partnerList.partnerList = data   
						that.goUrl = res.data.result.url
					}
				})
			},
			// 查看合同
			viewPartner(info) {
				let num = this.judgmentType(info.agency_level)
				uni.navigateTo({
					url: './contra-page/index?id=' + info.id + '&num=' + num
				})
			},
			viewPartners() {
				window.location.href = this.goUrl
			},
			// 返回上一页
			returnPrevious() {
				uni.navigateBack({
					delta: 2
				})
			},
			// 判断层级
			judgmentType(info){  
				let num;
				switch (info) {
					case '省级合伙人':
						num = 1
						break;
					case '市级合伙人':
						num = 2
						break;
					case '区/县合伙人':
						num = 3
						break;
					case '社群主':
						num = 4
						break
				}
				console.log(num)
				return num
			}
		}
	}
</script>

<style lang="less">
	.cooperation {
		position: relative;

		// 背景图
		.coopera_bann {
			height: 400rpx;
			background-image: linear-gradient(to bottom, #f34645, #fe8c43);

			.coopera_bann_img {
				margin: 0 auto;
				display: block;
				width: 100%;
				height: 100%;
			}
		}

		// 合伙人页面
		.peration_list {
			position: absolute;
			top: 300rpx;
			margin: 0 40rpx;
			width: calc(100% - 80rpx);
			background-color: #fff;
			border-radius: 30rpx;

			.peration_item {
				margin: 20rpx 0;
				display: flex;
				align-items: center;
				position: relative; 
				padding-right: 40rpx;
				height: 210rpx;
				color: #333;
				font-size: 36rpx;
				line-height: 200rpx; 
				box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.11);
				border-radius: 16px;
				.peration_item_t{ 
					width: 180rpx;
					height: 200rpx;
				}
				.peration_item_img{
					margin-top: 30rpx;
					width: 60rpx;
					height: 60rpx;
				} 

				 .peration_item_c {
					 margin-left: 20rpx;
					 display: flex;
					 flex-direction: column;
					flex: 1; 
					font-size: 34rpx;
					line-height: 90rpx; 
					& text:last-child{ 
						display: block;
						color: #6a6a6c;
						height: 60rpx;
						line-height: 60rpx;
						text-align: center;
						font-size: 24rpx;  
						border-radius: 20rpx;
						border: 1rpx solid #eee;
					}
				}
 
			}
		}
	}
</style>
